import { NgModule } from '@angular/core'
import { Routes, RouterModule } from '@angular/router'
import { SimpleGuard } from '@delon/auth'
import { environment } from '@env/environment'
// layout
import { LayoutDefaultComponent } from '../layout/default/default.component'
import { LayoutFullScreenComponent } from '../layout/fullscreen/fullscreen.component'
import { LayoutPassportComponent } from '../layout/passport/passport.component'
// passport pages
import { UserLoginComponent } from './passport/login/login.component'
import { UserRegisterComponent } from './passport/register/register.component'
import { UserRegisterResultComponent } from './passport/register-result/register-result.component'
// single pages
import { CallbackComponent } from './callback/callback.component'
import { UserLockComponent } from './passport/lock/lock.component'

import { AdminComponent } from './welcome/admin/admin.component'
import { EnindexComponent } from './welcome/enindex/enindex.component'
import { NewRouterGuardClass } from '@shared/classes/NewRouterGuardClass'

const routes: Routes = [
  {
    path: '',
    component: LayoutDefaultComponent,
    children: [
      {
        path: '',
        redirectTo: 'dashboard',
        pathMatch: 'full',
      },
      {
        path: 'dashboard',
        loadChildren: './dashboard/dashboard.module#DashboardModule'
      },
      {
        path: 'biz',
        loadChildren: './business/business.module#BusinessModule'
      },
      {
        path: 'users',
        loadChildren: './user/user.module#UserModule'
      },
      {
        path: 'roles',
        loadChildren: './role/role.module#RoleModule'
      },
      {
        path: 'menus',
        loadChildren: './menu/menu.module#MenuModule'
      },
      {
        path: 'trades',
        loadChildren: './trades/trades.module#TradesModule'
      },
      {
        path: 'operations',
        loadChildren: './operations/operations.module#OperationsModule'
      },
      {
        path: 'exception',
        loadChildren: './exception/exception.module#ExceptionModule'
      },
      {
        path: 'report',
        loadChildren: './report/report.module#ReportModule'
      },
      {
        path: 'risk',
        loadChildren: './risk/risk.module#RiskModule'
      },
      {
        path: 'postRisk',
        loadChildren: './post-risk/post-risk.module#PostRiskModule'
      },
      {
        path: 'postRiskEvent',
        loadChildren: './post-risk-event/post-risk-event.module#PostRiskEventModule'
      },
    ]
  },
  {
    path: 'default',
    component: LayoutDefaultComponent,
    canActivate: [SimpleGuard],
    children: [
      { path: '', redirectTo: 'dashboard', pathMatch: 'full' },
      { path: 'exception', loadChildren: './exception/exception.module#ExceptionModule' },
    ],
  },
  // {
  //   path: '',
  //   component: LayoutFullScreenComponent,
  //   children: [
  //     { path: '', redirectTo: 'index', pathMatch: 'full' },
  //     { path: 'index', component: AdminComponent },
  //     { path: 'eindex', component: EnindexComponent },
  //     // 业务子模块
  //     // { path: 'widgets', loadChildren: './widgets/widgets.module#WidgetsModule' }
  //   ],
  // },
  // 全屏布局
  // {
  //     path: 'fullscreen',
  //     component: LayoutFullScreenComponent,
  //     children: [
  //     ]
  // },
  // passport
  {
    path: 'passport',
    component: LayoutPassportComponent,
    children: [
      { path: 'login', component: UserLoginComponent, data: { title: '登录', titleI18n: 'BTN.LOGIN' } },
      { path: 'register', component: UserRegisterComponent, data: { title: '注册' } },
      { path: 'register-result', component: UserRegisterResultComponent, data: { title: '注册结果' } },
      { path: 'lock', component: UserLockComponent, data: { title: '锁屏' } },
    ],
  },
  // 单页不包裹Layout
  { path: 'callback/:type', component: CallbackComponent },
  { path: '**', redirectTo: 'exception/404' },
]

@NgModule({
  imports: [
    RouterModule.forRoot(routes, {
      useHash: false,
      // NOTICE: If you use `reuse-tab` component and turn on keepingScroll you can set to `disabled`
      // Pls refer to https://ng-alain.com/components/reuse-tab
      scrollPositionRestoration: 'disabled',
    }),
  ],
  exports: [RouterModule],
  providers: [NewRouterGuardClass],
})
export class RouteRoutingModule {}
